
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网关测试页面</title>
</head>
<body>
<form action="gateway.htm" id="testForm"
	method="post">

<table>
	<tr>
		<td>商户号</td>
		<td><input type="text" value="11001234567" name="member_code"
			id="member_code" />*</td>
	</tr>
	<tr>
		<td>卡号</td>
		<td><input type="text" name="card_no" id="card_no" maxlength="25"
			value="03512265325418459" /></td>
	</tr>
	<tr>
		<td>卡密</td>
		<td><input type="text" name="card_pwd" id="card_pwd"
			maxlength="25" value="035122653254184590" /></td>
	</tr>
	<tr>
		<td>支付结果展现页面</td>
		<td><input type="text" name="redirect_url" id="redirect_url" value=""
			size="100">*</td>
	</tr>
	<tr>
		<td>常用接收结果地址</td>
		<td><input type="text" size="60" name="notify_url"
			id="notify_url" value="http://www.baidu.com" /></td>
	</tr>
	<tr>
		<td>网关版本</td>
		<td><input type="text" value="1.0" name="version" id="version" />*
		</td>
	</tr>
	<tr>
		<td>网关版本</td>
		<td><input type="hidden"" value="1.0" name="ver_sion" id="ver_sion" />*
		</td>
	</tr>
	<tr>
		<td>验签</td>
		<td><input type="text" name="sign_msg" id="sign_msg" readonly /></td>
	</tr>
	<tr>
		<td>订单号</td>
		<td><input type="text" value="725024134141131321" name="order_id"
			id="order_id" /></td>
	</tr>
	<tr>
		<td>订单金额</td>
		<td><input type="text" value="10000" name="order_amount"
			id="order_amount" />*</td>
	</tr>
	<tr>
		<td>提交时间</td>
		<td><input type="text" name="order_time" id="order_time"
			value="20130205141200" /></td>
	</tr>
	<tr>
		<td>商品名称</td>
		<td><input type="text" name="product_name" id="product_name"
			value="QQ币" /></td>
	</tr>
	<tr>
		<td>返回结果的方式</td>
		<td><input type="text" name="ret_mode" id="ret_mode" value="view" />xml,txt</td>
	</tr>
	<tr>
		<td>备用字段1</td>
		<td><input type="text" name="ext1" id="ext1" value="测试1" /></td>
	</tr>
	<tr>
		<td>备用字段2</td>
		<td><input type="text" name="ext2" id="ext2" value="测试2" /></td>
	</tr>
	<tr>
		<td>商家key</td>
		<td><input type="text" value="mo198682" name="key" id="key" />*</td>
	</tr>
	<tr>
		<td><input type="button" value="生成加密字段"
			onclick="getOrderId();encode();" /></td>
		<td><input type="button" value="提交网关" onclick="checkForm();" /></td>
	</tr>
</table>
</form>
</body>
<script type="text/javascript">
var xmlHttp;
var fieldArr = new Array("version","member_code","order_time","order_id","order_amount","card_no","card_pwd","key","ver_sion");
	function encode(){
		if(isNull(document.getElementById('key').value)) {
			alert('key不能为空');
		} 
		var url = "testencode.htm?"+getKey();
		callback = function() {
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					var  result= xmlHttp.responseText;
					var r=result.split(";");
					document.getElementById("card_no").value=r[1];
					document.getElementById("card_pwd").value=r[2];
					document.getElementById("sign_msg").value=r[0];
				}
			}
		}
		sendRequest(url,callback);
	}

	function getOrderId(){
		var myDate = new Date();
		document.getElementById("order_id").value=myDate.getTime();        
	}

	function isNull(s){
	    if (s == null || s.length <= 0 || trim(s) == ""){
	            return true;
	    }
	    return false;
	}
	
	function trim(strSrc)
	{
		return strSrc.replace(/(^\s*)|(\s*$)/g, "");
	}
	
	function checkForm(){
		if(isNull(document.getElementById('key').value)) {
			alert('key不能为空');
		} else {
			document.getElementById('testForm').submit();
		}
	}
	
	function getKey(){
		var key = '';
		for(var i = 0;i<fieldArr.length;i++) {
			if(!isNull(document.getElementById(fieldArr[i]).value)){
				key += fieldArr[i] + '=' +document.getElementById(fieldArr[i]).value + '&' ;
			}
		}
		//alert(key);
		return key;
	}
	function sendRequest(url,callback) {
		xmlHttp = createXMLHttpRequest();
		xmlHttp.onreadystatechange = callback;
		xmlHttp.open("POST", url, true);
		xmlHttp.send(null);
	}

	function createXMLHttpRequest() {
		if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
			}
		}
		return xmlHttp;
	}
</script>
</html>